<%--
  Created by IntelliJ IDEA.
  User: Liutong
  Date: 2016/1/13
  Time: 14:06
  To change this template use File | Settings | File Templates.
--%>
<%@ page import="com.salesmanager.core.constants.Constants" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ taglib uri="http://www.springframework.org/tags" prefix="s" %>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<%@ taglib prefix="sm" uri="/shopizer-tags" %>
<%@ taglib prefix="input" uri="http://www.springframework.org/tags/form" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<div class="container-breadcrumb">
    <div class="row ">
        <div class="col-sm-12">
            <ol class="breadcrumb">
                <li><a href="#"><span class="glyphicon glyphicon-home"></span></a></li>
                <li>安卓渠道</li>
                <li class="active">
                    <c:if test="${channelId==null}"><s:message text="新建渠道"/></c:if>
                    <c:if test="${channelId!=null}"><s:message text="编辑渠道"/></c:if>
                </li>
            </ol>
        </div>
    </div><!--/.row-->
</div>
<div id="container-content" class="container-content">
    <div class="panel panel-default">
        <div class="panel-heading">
            <c:choose>
                <c:when test="${configuration.androidChannel.id!=null}">
                    编辑渠道
                </c:when>
                <c:otherwise>
                    新建渠道
                </c:otherwise>
            </c:choose>
        </div>
        <form:form id="myForm" method="POST" cssClass="form-horizontal" commandName="configuration" enctype="multipart/form-data"
                   action="${pageContext.request.contextPath}/channel/saveChannel">
            <div class="panel-body">
                <div class="form-group">
                    <label class="col-sm-2 control-label">渠道编码 ：</label>
                    <div class="col-sm-6">
                        <c:if test="${channelId==null}"><form:input cssClass="form-control" id="channelCode" path="androidChannel.channelCode"/></c:if>
                        <c:if test="${channelId!=null}">
                            <p class="form-control-static">${configuration.androidChannel.channelCode}</p>
                            <form:hidden path="androidChannel.channelCode" />
                        </c:if>
                    </div>
                    <codeWrong style="color: red"></codeWrong>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">渠道名称 ：</label>
                    <div class="col-sm-6">
                        <form:input cssClass="form-control" id="channelName" path="androidChannel.channelName"/>
                    </div>
                    <nameWrong style="color: red"></nameWrong>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">是否强制升级</label>
                    <div class="col-sm-2">
                        <form:select path="androidChannel.requiredUpdate" class="form-control">
                            <form:option value="" label="请选择"/>
                            <form:option value="1"  label="是"/>
                            <form:option value="0"  label="否"/>
                        </form:select>
                    </div>
                </div>

                <div class="form-group"><h3>APK信息</h3></div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">文件 ：</label>
                    <div class="col-sm-4">
                        <p id="fileName" class="form-control-static">${configuration.androidChannel.fileName}</p>
                    </div>
                    <div class="col-sm-2">
                        <input type="file" id="uploadFile" name="channelFile" onchange="javascript:mysub()">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">文件大小 ：</label>
                    <div class="col-sm-6">
                        <p id="fileSize" class="form-control-static">${configuration.androidChannel.fileSize}</p>
                    </div>
                    <sizeWrong style="color: red"></sizeWrong>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">文件MD5 ：</label>
                    <div class="col-sm-6">
                        <p class="form-control-static">${configuration.androidChannel.fileMd5}</p>
                    </div>
                    <md5Wrong style="color: red"></md5Wrong>
                </div>
                <div class="form-group"><h3>版本信息</h3></div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">外部版本号 ：</label>
                    <div class="col-sm-6">
                        <form:input cssClass="form-control" id="version" path="androidChannel.version"/>
                    </div>
                    <verWrong style="color: red"></verWrong>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">内部版本号 ：</label>
                    <div class="col-sm-6">
                        <form:input cssClass="form-control" id="innerVersion" path="androidChannel.innerVersion"/>
                    </div>
                    <inVWrong style="color: red"></inVWrong>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">版本描述 ：</label>
                    <div class="col-sm-6">
                        <form:textarea cssClass="form-control" id="versionDesc" path="androidChannel.versionDesc" />
                    </div>
                </div>
                <form:hidden path="androidChannel.id" />
            </div>
            <div class="panel-footer">
                <button id="channelSubmit" type="button" class="btn btn-success"><s:message code="button.label.submit2" text="Submit"/></button>
            </div>
        </form:form>
    </div>
</div>
<div class="modal fade" id="UPLOADFILE" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
     data-backdrop="static">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" style="font-size: 18px;">文件上传中...</h5>
            </div>
            <div class="modal-body">
                <div class="progress">
                    <div class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100" style="width: 100%">
                        <span class="sr-only">100% Complete</span>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


<script>
    function mysub(){
        var dom = document.getElementById("uploadFile");
        var fileSize =  dom.files[0].size;
        var filename = dom.files[0].name;
        var index1=filename.lastIndexOf(".");
        var index2=filename.length;
        var postf=filename.substring(index1+1,index2);
        if(postf.toUpperCase()!='APK'){
            alert("只允许上传apk文件，请重新选择");
            return false;
        }
        var dom2 = document.getElementById("fileSize");
        dom2.innerHTML=fileSize;
        var element = document.getElementById("fileName");
        element.innerHTML = filename;
    }

    $(document).ready(function () {
        $("#channelSubmit").click(function(){
            var dom = document.getElementById("uploadFile");
            if(dom.files.length!=0){
                var filename = dom.files[0].name;
                var index1=filename.lastIndexOf(".");
                var index2=filename.length;
                var postf=filename.substring(index1+1,index2);
                if(postf.toUpperCase()!='APK'){
                    alert("只允许上传apk文件，请重新选择");
                    return false;
                }
            }
            var code = $("#channelCode").val();
            var name = $("#channelName").val();
            var version = $("#version").val();
            var innerVersion = $("#innerVersion").val();
            if(code==''){
                $("codeWrong").html("渠道编码不能为空");
                return false;
            }
            if(name==''){
                $("nameWrong").html("渠道名称不能为空");
                return false;
            }
            if(version==''){
                $("verWrong").html("外部版本号不能为空");
                return false;
            }
            if(innerVersion==''){
                $("inVWrong").html("内部版本号不能为空");
                return false;
            }
            $('#UPLOADFILE').modal("show");
            $("form").submit();
        });

        $("#channelCode").change(function(){
            var code = $("#channelCode").val();
            if(code!=''){
                $("codeWrong").html("");
            }
        });
        $("#channelName").change(function(){
            var name = $("#channelName").val();
            if(name!=''){
                $("nameWrong").html("");
            }
        });
        $("#version").change(function(){
            var version = $("#version").val();
            if(version!=''){
                $("verWrong").html("");
            }
        });
        $("#innerVersion").change(function(){
            var innerVersion = $("#innerVersion").val();
            if(innerVersion!=''){
                $("inVWrong").html("");
            }
        });

    });
</script>

